/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormularioSeccion.java
 *
 * Created on 19/02/2011, 03:55:17 PM
 */

package vistas;

import clases.Seccion;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author 
 */
public class FormularioSeccion extends javax.swing.JFrame {

     private Seccion seccion;


    public void setSeccion(Seccion seccion) {
        this.seccion = seccion;
    }

    /** Creates new form FormularioSeccion */
    public FormularioSeccion() {
        initComponents();
    }

    public void cancelar(){
        txtNum.setText("");
    }

      public boolean validarVacios(){
        if(txtNum.getText().equals(""))
                return false;
            else
                return true;
   }

   public boolean validarNumero(){
        try {
            if(Integer.parseInt(txtNum.getText())>0)
                return true;
            else
                return false;
	} catch (NumberFormatException e) {
            return false;
        }
   }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        txtNum = new javax.swing.JTextField();
        btnCancelar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        btnCrear = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel4.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel4.setText("Numero de la Seccion:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(30, 30, 170, 20);
        getContentPane().add(txtNum);
        txtNum.setBounds(220, 30, 90, 28);

        btnCancelar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelar);
        btnCancelar.setBounds(140, 110, 110, 30);

        btnSalir.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalir);
        btnSalir.setBounds(140, 150, 110, 30);

        btnCrear.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnCrear.setText("Crear");
        btnCrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCrearActionPerformed(evt);
            }
        });
        getContentPane().add(btnCrear);
        btnCrear.setBounds(140, 70, 110, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-414)/2, (screenSize.height-251)/2, 414, 251);
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        cancelar();
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        dispose();
}//GEN-LAST:event_btnSalirActionPerformed

    private void btnCrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrearActionPerformed
        // TODO add your handling code here:
         if(validarVacios())
            if(validarNumero()){
                  
                 
                    seccion.setNumeroseccion(Integer.parseInt(txtNum.getText()));
                    JOptionPane.showMessageDialog(new JFrame(),"Seccion creada","Seccion",JOptionPane.INFORMATION_MESSAGE);
                    cancelar();
                }
            else
                JOptionPane.showMessageDialog(new JFrame(),"Numero invalido","Seccion",JOptionPane.WARNING_MESSAGE);
        else
            JOptionPane.showMessageDialog(new JFrame(),"Campos vacios","Seccion",JOptionPane.WARNING_MESSAGE);


}//GEN-LAST:event_btnCrearActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormularioSeccion().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCrear;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField txtNum;
    // End of variables declaration//GEN-END:variables

}
